//
//  LLSaveImageTool.m
//  TaoTuo
//
//  Created by admin on 2019/12/25.
//  Copyright © 2019 admin. All rights reserved.
//

#import "LLSaveImageTool.h"
#import <Photos/Photos.h>

@implementation LLSaveImageTool

- (void)saveImage:(UIImage *)image
{
    [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
        
        dispatch_async(dispatch_get_main_queue(), ^{
        
            if (status == PHAuthorizationStatusDenied || status == PHAuthorizationStatusRestricted) {
                [LLAlertUtilies showSystemSetAlertViewWithTitle:@"开启相册权限" message:@"开启后才能保存图片到相册" cancelTitle:nil confirmTitle:@"去开启"];
                
            } else {
                UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
            }
            
        });
        
    }];
    
}

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    UIView *window = [UIApplication sharedApplication].keyWindow;
    if (error) {
        [window makeToast:@"保存失败"];
    } else {
        [window makeToast:@"保存成功"];
    }
}

@end
